import pandas as pd

columns_dict = {"姓名": "name", "手机号": "mobile", "国家": "iso_code", "邮箱": "email", "性别": "gender",
                "出生日期": "birth", "语言": "lang"}


async def read_file(file_path, data_format, save_data):
    """
    read file and save
    :param file_path: file path
    :param data_format: function
    :param save_data: function
    :return:
    """
    data = pd.read_excel(file_path,dtype=str)
    columns_name = [column for column in data]
    keys = columns_dict.keys()

    ext_list = list(set(columns_name).difference(set(keys)))
    # print(ext_list)
    pool_list = []
    pool_ext_list = []
    for i, line in data.iterrows():

        pool, pool_ext = await data_format(line, ext_list)
        if pool is None:
            continue
        pool_list.append(pool)
        pool_ext_list += pool_ext
        if i != 0 and i % 200 == 0:
            await save_data(pool_list, pool_ext_list)
            pool_list = []
            pool_ext_list = []

    await save_data(pool_list, pool_ext_list)


if __name__ == '__main__':
    read_file("/home/herb/work/send_email_service/auto_sell_service/pool/temp/123.xlsx")

    # for dd in gen(10):
    #     print(dd)
